# -*- coding: utf-8 -*-
import logging
import sys

from pyspark import SparkContext, conf

from pyspark.sql import SparkSession

if __name__ == '__main__':

    if len(sys.argv) < 3:
        logging.error("参数异常，需要输入文件名。")
        exit(0)

    file_name = sys.argv[1]
    table_name = sys.argv[2]

    spark = SparkSession.builder.enableHiveSupport().appName("mazeng_adv_topic")\
        .config("spark.serializer", "org.apache.spark.serializer.KryoSerializer")\
        .config("spark.kryoserializer.buffer", "10").getOrCreate()

    srcDF = spark.read.format("csv").option("header", "true").option("delimiter", ",")\
        .load(f"oss://emr-datalake.cn-beijing.oss-dls.aliyuncs.com/test/{file_name}")
    srcDF.createTempView("temp_tbl")

    spark.sql(f"""
    drop table if exists temp.{table_name}
        """)
    
    resultDF = spark.sql(f"""
    create table temp.{table_name}
     select *  from temp_tbl 
    """)
    resultDF.show(2)

    spark.stop()










